package com.yonyou.cyxdms.sysAuth.service.utill;

import cz.mallat.uasparser.OnlineUpdater;
import cz.mallat.uasparser.UASparser;
import cz.mallat.uasparser.UserAgentInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @Description UserAgent工具类
 * @Author zouhu
 * @Date 2019/2/15/015 17:33
 * @Version 1.1.0
 */
public class UserAgentUtils {

    // 定义日志接口getMenus
    private static final Logger logger = LoggerFactory.getLogger(UserAgentUtils.class);

    public static UASparser uasParser = null;

    // 初始化uasParser对象
    static {
        try {
            uasParser = new UASparser(OnlineUpdater.getVendoredInputStream());
        } catch (IOException e) {
            logger.error("初始化uasParser对象失败", e);
        }
    }

//    public static void main(String[] args) {
//        String str = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36";
//        System.out.println(str);
//        try {
//            UserAgentInfo userAgentInfo = UserAgentUtils.uasParser.parse(str);
//            System.out.println("操作系统名称：" + userAgentInfo.getOsFamily());//
//            System.out.println("操作系统：" + userAgentInfo.getOsName());//
//            System.out.println("浏览器名称：" + userAgentInfo.getUaFamily());//
//            System.out.println("浏览器版本：" + userAgentInfo.getBrowserVersionInfo());//
//            System.out.println("设备类型：" + userAgentInfo.getDeviceType());
//            System.out.println("浏览器:" + userAgentInfo.getUaName());
//            System.out.println("类型：" + userAgentInfo.getType());
//            System.out.println(userAgentInfo.toString());
//
//        } catch (IOException e) {
//            logger.error("获取uasParser对象失败", e);
//        }
//    }
}